package home

import "fmt"

/**
*    b          t
* 0,0 -> 0   0,0 -> 0
* 0,1 -> 0   0,1 -> 1
* 0,2 -> 1   0,2 -> 0
* 1,0 -> 1   1,0 -> 1
* 1,1 -> 2   1,1 -> 0
* 1,2 -> 2   1,2 -> 1
 */

func gT(t, b uint64) uint64 {
	b1 := (b & 2) >> 1
	b0 := b & 1
	r := t ^ b1 ^ b0
	fmt.Printf("t:%b  b:%b  r:%b\n", t, b, r)
	return r
}

func gB(t, b uint64) uint64 {
	b1 := (b & 2) >> 1
	b0 := b & 1
	r := (t | b1) | ((t & b0) << 1)
	fmt.Printf("t:%b  b:%b  r:%b\n", t, b, r)
	return r
}

var tl1 [6][3]uint64 = [6][3]uint64{
	{0b000, 0b000, 0b000},
	{0b000, 0b001, 0b100},
	{0b000, 0b011, 0b000},
	{0b100, 0b000, 0b100},
	{0b100, 0b001, 0b000},
	{0b100, 0b011, 0b100},
}

func ftl1() {
	for _, f := range FS4H {
		got := true
		for _, r := range tl1 {
			if got && f.fn(uint8(r[0]), uint8(r[1])) == uint8(r[2]) {
				continue
			} else {
				got = false
			}
		}
		if got {
			fmt.Println(f.str)
		}
	}

	// p ^ Mv_l2((0b001&n))
}

var bl1 [6][3]uint64 = [6][3]uint64{
	{0b000, 0b000, 0b000},
	{0b000, 0b001, 0b000},
	{0b000, 0b011, 0b001},
	{0b100, 0b000, 0b001},
	{0b100, 0b001, 0b011},
	{0b100, 0b011, 0b011},
}

func fbl1() {
	for _, f := range FS4H {
		got := true
		for _, r := range bl1[3:6] {
			if got && f.fn(uint8(r[0]), uint8(r[1])) == uint8(r[2]) {
				continue
			} else {
				got = false
			}
		}
		if got {
			fmt.Println(f.str)
		}
	}

	// nothing

	/*
		bl1[0:3]
			(0b001|p) & Mv_l2(n)
			(0b001^p) & Mv_l2(n)
			p | Mv_l2((0b010&n))
			p ^ Mv_l2((0b010&n))
			^p & Mv_l2((0b010&n))
		bl1[3:6]
			nothing
	*/
}

func fdv2() {
	for i := 0; i < 8; i++ {
		gotA, gotO, gotX := true, true, true
		for j := 0; j < 3; j++ {
			if gotA && (j/2 == i&j) {
				continue
			} else {
				gotA = false
			}
		}
		if gotA {
			fmt.Println(i, "&")
		}
		for j := 0; j < 3; j++ {
			if gotO && (j/2 == i|j) {
				continue
			} else {
				gotO = false
			}
		}
		if gotA {
			fmt.Println(i, "|")
		}
		for j := 0; j < 3; j++ {
			if gotX && (j/2 == i^j) {
				continue
			} else {
				gotX = false
			}

		}
		if gotA {
			fmt.Println(i, "^")
		}
	}
}
